package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.GoodsType;
import cn.wolfcode.trip.base.mapper.GoodsTypeMapper;
import cn.wolfcode.trip.base.query.GoodsTypeQueryObject;
import cn.wolfcode.trip.base.service.IGoodsTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsTypeServiceImpl implements IGoodsTypeService {

    @Autowired
    private GoodsTypeMapper goodsTypeMapper;


    public List<GoodsType> listForState(Integer state) {
        return goodsTypeMapper.selectType(state);
    }

    public List<GoodsType> listAll() {
        return goodsTypeMapper.selectAll();
    }

    public PageInfo<GoodsType> selectForList(GoodsTypeQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<GoodsType> list = goodsTypeMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    public void saveOrUpdate(GoodsType goodsType) {
        if (goodsType.getId() == null){
            goodsTypeMapper.insert(goodsType);
        }else {
            goodsTypeMapper.updateByPrimaryKey(goodsType);
        }
    }

    public void delete(Long id) {
        goodsTypeMapper.deleteByPrimaryKey(id);
    }
}
